package com.wangzaiplus.test.juc.thread;

/**
 * @ClassName Demo06
 * @Description: TODO
 * @Author wgc
 * @Date 2020/06/28 10:30
 * @Version V1.0
 **/
public class Demo06 {
    static Object object=new Object();
    public  static  class T1 extends  Thread{
        @Override
        public void run() {
            synchronized (object){
                System.out.println(System.currentTimeMillis()+"T1 start");
                System.out.println(System.currentTimeMillis()+"T1 wait for Object");
                try {
                    object.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(System.currentTimeMillis()+"T1 end");

            }
        }
    }

    public  static  class T2 extends  Thread{
        @Override
        public void run() {
            synchronized (object){
                System.out.println(System.currentTimeMillis()+"T2 start  notify one");
                object.notify();
                System.out.println(System.currentTimeMillis()+"T2 end");

                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(System.currentTimeMillis()+"T1 end");

            }
        }
    }

    public static void main(String[] args){
       new T1().start();
        new T2().start();
    }
}
